<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
$wxsetting = $_G['cache']['plugin']['hux_toweixin'];
$weixintishi = explode('|',$wxsetting['tishi']);
if ($wxsetting['mobile'] == 1) {
	$mobile = '&mobile=no';
} elseif ($wxsetting['mobile'] == 2) {
	$mobile = '&mobile=2';
} elseif ($wxsetting['mobile'] == 3) {
	$mobile = '&mobile=yes';
} else {
	$mobile = '';
}
$urlToEncode = str_replace('&','%26',$_GET['chl'].$mobile);
$qrout = generateQRfromGoogle($urlToEncode);

include template('hux_toweixin:index');

function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0') {
	global $wxsetting,$weixintishi;
	//$url = urlencode($url);
	$margin = $wxsetting['margin'];
	$widhtHeight = $wxsetting['size'];
	$EC_level = $wxsetting['level'];
	if ($wxsetting['api'] == 1) {
		$r = '<img src="http://chart.apis.google.com/chart?chs=220x220&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="'.$weixintishi[1].'" widhtHeight="'.$widhtHeight.'" widhtHeight="'.$widhtHeight.'"/>';
	} elseif ($wxsetting['api'] == 2) {
		$bg = str_replace('#','',$wxsetting['bg']);
		$fg = str_replace('#','',$wxsetting['fg']);
		$gc = str_replace('#','',$wxsetting['gc']);
		$pt = str_replace('#','',$wxsetting['pt']);
		$inpt = str_replace('#','',$wxsetting['inpt']);
		$r = '<img src="http://qr.liantu.com/api.php?bg='.$bg.'&fg='.$fg.'&gc='.$gc.'&el='.strtolower($EC_level).'&w='.$widhtHeight.'&m='.$margin.'&pt='.$pt.'&inpt='.$inpt.'&logo='.$wxsetting['logo'].'&text='.$chl.'"/>';
	} else {
		$bg = str_replace('#','',$wxsetting['bg']);
		$fg = str_replace('#','',$wxsetting['fg']);
		$widhtHeight = intval($widhtHeight / 44);
		$r = '<img src="http://huxapi.duapp.com/index.php?action=qr&bg='.$bg.'&fg='.$fg.'&el='.$EC_level.'&mps='.$widhtHeight.'&m='.$margin.'&val='.$chl.'"/>';
	}
	return $r;
}
?>